import request from "./index";

/**
 * 文章列表接口
 * @param userId {string | number}
 * @param offset {string | number}
 * @param limit {string | number}
 * @returns {Promise}
 */
export function getArticleList(userId, offset, limit) {
  return request({
    url: "/article/list",
    params: {
      userId,
      offset,
      limit
    }
  })
}

/**
 * 获取文章详情
 * @param id {string | number}
 * @returns {Promise}
 */
export function getArticleDetail(id) {
  return request({
    url: "/article",
    params: {
      id
    }
  })
}

/**
 * 创建一篇文章
 * @param title {string}
 * @param classifyId {string | number}
 * @param content {string}
 * @param count {number}
 * @returns {Promise}
 */
export function createArticle(title, classifyId, content, count) {
  return request({
    url: "/article",
    method: "POST",
    data: {
      title,
      classifyId,
      content,
      count
    }
  })
}

/**
 * 修改一篇文章
 * @param title {string}
 * @param classifyId {string | number}
 * @param content {string}
 * @param count {number}
 * @param articleId {string | number}
 * @returns {Promise}
 */
export function updateArticle(title, classifyId, content, count, articleId) {
  return request({
    url: "/article",
    method: "PATCH",
    data: {
      title,
      classifyId,
      content,
      count,
      articleId
    }
  })
}

/**
 * 删除一篇文章
 * @param articleId {string | number}
 * @returns {Promise}
 */
export function deleteArticle(articleId) {
  return request({
    url: `/article/${articleId}`,
    method: "DELETE"
  })
}

